<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: mapi_control_index.php 3729 2014-01-02 08:34:11Z laoguozhang $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class stat_control_report extends stat_base_control
{
    public $uin;
    public $cache_prefix;

	public function __construct() {
		parent::__construct();
        $this->uin = $this->request()->post_string('uin');
        $this->cache_prefix = 'wsq_follow_';
	}
	
	/**
	 * lol 看帖页面 上报数据
	 */
	public function action_viewthread() {
        //$this->_send(3003);
		$param = array(
			'oper_type' => 3003,
		);
		$this->send($param);
	}

    /**
     * lol 发帖页面 上报数据
     */
    public function action_newthread() {
        //$this->_send(3004);
		$param = array(
			'oper_type' => 3004,
		);
		$this->send($param);
    }

    /**
     * lol 回贴页面 上报数据
     */
    public function action_sendreply() {
        //$this->_send(3005);
		$param = array(
			'oper_type' => 3005,
		);
		$this->send($param);
    }

    /**
     * lol 上传图片页面 上报数据
     */
    public function action_upload() {
        //$this->_send(3018);
		$param = array(
			'oper_type' => 3018,
		);
		$this->send($param);
    }

    /**
     * lol 赞 上报数据
     */
    public function action_recommend() {
		//$this->_send(3020);
		$param = array(
			'oper_type' => 3020,
		);
		$this->send($param);
    }

    /**
     * 主题列表页 上报数据
     */
    public function action_forumdisplay() {
		//$this->_send(3002);
		$param = array(
			'oper_type' => 3002,
		);
		$this->send($param);
    }

    public function action_forumindex() {
		//$this->_send(3037);
		$param = array(
			'oper_type' => 3037,
		);
		$this->send($param);
    }

    /**
     * 发帖关注主账号和站点
     */
    public function action_sitefollow() {
		$sid = $this->request()->get_string('g_id');
        $user = DZF::t('wsq_site_follow')->fetch_by_uin_sid($this->uin, $sid);

		//同一UIN关注主账号只上报一次
        if(empty($user[$this->cache_prefix.$this->uin])) {
            //$this->_send(3034, false);
			$param = array(
				'oper_type' => 3034,
				'msg4' => 'inner',
				'msg5' => $this->request()->get_string('msg5'),
			);
			$this->send($param, false);
			unset($param);
        }
		
		//同一UIN同一站点的关注只上报一次
		if(empty($user[$this->cache_prefix.$this->uin.'_'.$sid])) {
			DZF::t('wsq_site_follow')->insert(array('uin' => $this->uin, 'sid' => $sid, 'dateline' => TIMESTAMP));
			//$this->_send(3027, false);//添加 inner
			$param = array(
				'oper_type' => 3027
			);
			
			if($this->request()->post_string('from') === 'pc') {
				$param['msg4'] = 'inner';
				$param['msg5'] = $this->request()->get_string('msg5');
			}
			$this->send($param, false);
			unset($param);
		}
		//
		if($this->request()->post_string('mobileqqnotice')){
			//$this->_send(3039);
			$param = array(
				'oper_type' => 3039,
				'g_type' => '3',
			);
			$this->send($param);
			unset($param);
		}
    }
	
	/**
     * 用户发帖时主动取消手机QQ通知功能
     */
    public function action_cancelmobileqqnotice() {
		//$this->_send(3038);
		$param = array(
			'oper_type' => 3038,
			'g_type' => '3',
		);
		$this->send($param);
    }

	public function send($param, $exit = true) {
		
		$this->make_cors($_SERVER['REQUEST_METHOD'], 'http://open.wsq.qq.com');
		
        $data = array(
			'userip' => $this->request()->get_string('clientip'),
            'username' => $this->request()->get_string('username'),
            'g_id' => $this->request()->get_string('g_id'),
            'g_name' => $this->request()->get_string('g_name'),
            //'oper_type' => $oper_type,
            'cookie' => $this->uin,
            'ext2' => $this->request()->post_string('ext2'),
            'msg2' => $this->request()->post_string('msg2'),
            'msg3' => $this->request()->get_string('msg3'),
            'msg4' => '',
            'msg5' => '',
		);
		
		$data = (array)$param + (array)$data;
		
		$g_type = array('app' => 99, 'wx' => 100);
		$from = $this->request()->get_string('from');
		//第三方自己的APP生产的数据（lol app）
		if(isset($g_type[$from])) {
			$data['g_type'] = $g_type[$from];
		}
		
		DZF::ext('dc')->writeLog($data);
		
		if($exit) {
			$this->http_204_exit();
		}
	}
	
	/**
	 * HTTP/1.0 204 No Content
	 */
	public function http_204_exit() {
		header("status: 204");
		header('HTTP/1.0 204 No Content');
		header('Content-Length: 0',true);
		flush();
		exit();
	}
	
	
    function _send($oper_type, $exit = true) {
		return false;
        //只有3034关注主账号的操作才传入$msg4 和 $msg5
        if($oper_type === 3034) {
            $msg4 = 'inner';
            $msg5 = $this->request()->get_string('msg5');
        } else {
            $msg4 = '';
            $msg5 = '';
        }
        $data = array(
			'userip' => $this->request()->get_string('clientip'),
            'username' => $this->request()->get_string('username'),
            'g_id' => $this->request()->get_string('g_id'),
            'g_name' => $this->request()->get_string('g_name'),
            'oper_type' => $oper_type,
            'cookie' => $this->uin,
            'ext2' => $this->request()->post_string('ext2'),
            'msg2' => $this->request()->post_string('msg2'),
            'msg3' => $this->request()->get_string('msg3'),
            'msg4' => $msg4,
            'msg5' => $msg5,
		);
		
		if($oper_type === 3038 || $oper_type === 3039) {
			$data['g_type'] = '3';
		}
		
		DZF::ext('dc')->writeLog($data);
		
		if($exit) {
			header("status: 204");
			header('HTTP/1.0 204 No Content');
			header('Content-Length: 0',true);
			flush();
			exit();
		}
    }
	
}
